//
//  RewardVideoVC.m
//  CJModileAdDemo
//
//  Created by JUN on 2022/3/6.
//

#import "RewardVideoVC.h"
#import "CustomShowView.h"
#import <AMPSAdSDK/AMPSAdSDK.h>

@interface RewardVideoVC ()<AMPSRewardedVideoAdDelegate>

@property (nonatomic, strong) AMPSRewardedVideoAd *rewardedVideoAd;

@end

@implementation RewardVideoVC

@synthesize customView = _customView;

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)dealloc
{
    NSLog(@"事件:%s", __FUNCTION__);
}
 
- (void)loadAdData {
    [self.rewardedVideoAd loadRewardedVideoAd];
}

- (AMPSRewardedVideoAd *)rewardedVideoAd {
    if (!_rewardedVideoAd) {
        _rewardedVideoAd = [[AMPSRewardedVideoAd alloc]initWithSpaceId:@"124547" adConfiguration:[AMPSAdConfiguration new]];
        _rewardedVideoAd.delegate = self;
    }
    return _rewardedVideoAd;
}

- (void)setupUI {
    self.title = @"RewardVideoAd";
    [self.view addSubview:self.customView];
    self.customView.frame = CGRectMake(0, 100, 200, 200);
    self.customView.center = self.view.center;
}

- (void)handleEvent:(NSInteger)eve {
    if (eve == 0) {
        [self loadAdData];
        return;
    }
}

- (CustomShowView *)customView {
    if (!_customView) {
        _customView = [[CustomShowView alloc] init];
        __weak RewardVideoVC *weakSelf = self;
        _customView.event = ^(NSInteger eve) {
            [weakSelf handleEvent:eve];
        };
    }
    return _customView;
}

#pragma mark CJRewardVideoAdDelegate
- (void)ampsRewardedVideoAdLoadSuccess:(AMPSRewardedVideoAd *)rewardedVideoAd {
    [self.rewardedVideoAd showRewardedVideoAdWithRootViewController:self];
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)ampsRewardedVideoAdLoadFail:(AMPSRewardedVideoAd *)rewardedVideoAd
                              error:(NSError *_Nullable)error {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)ampsRewardedVideoAdDidShow:(AMPSRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)ampsRewardedVideoAdDidClick:(AMPSRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)ampsRewardedVideoAdDidClose:(AMPSRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)ampsRewardedVideoAdDidPlayFinish:(AMPSRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)ampsRewardedVideoAdDidRewardEffective:(AMPSRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"事件:%s", __FUNCTION__);
}
@end
